package com.chagee.store.operation.server.facade;

import com.alibaba.fastjson.JSON;
import com.chagee.base.utils.*;
import com.chagee.store.operation.api.request.AcceptanceOrderRequest;
import com.chagee.store.operation.api.request.AcceptanceRequest;
import com.chagee.store.operation.server.model.param.*;
import com.chagee.store.operation.server.model.vo.ScanResponse;
import com.chagee.store.operation.server.model.vo.StoreMonthOrderVO;
import com.chagee.store.operation.server.model.vo.StoreOderInfoVO;
import com.chagee.store.operation.server.model.vo.QueryStoreTaskResponse;
import com.chagee.store.operation.server.service.StoreAppSweepService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * @Author : hk
 * @Date : 2024/7/31
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class StoreAppSweepFacade {

	@Resource
	private StoreAppSweepService storeAppSweepService;

	public PaginationData<QueryStoreTaskResponse> queryList(PaginationRequest<StoreAppSweepQueryParam> request) {
		return storeAppSweepService.queryList(request);
	}

	public PaginationData<QueryStoreTaskResponse> queryOrderTaskList(PaginationRequest<OrderTaskListParam> request) {
		return storeAppSweepService.queryOrderTaskList(request);
	}

	/**
	 * 门店本月单据状态详情
	 * @param param
	 * @return
	 */
	public StoreMonthOrderVO storeMonthOrder(MonthOrderParam param) {
		StoreMonthOrderVO storeMonthOrderVO = storeAppSweepService.storeMonthOrder(param);
		return storeMonthOrderVO;
	}

	/**
	 * 门店最近打烊工单日期
	 * @param param
	 * @return
	 */
	public String queryOrderDate(StoreWordInfoParam param) {

		return storeAppSweepService.queryOrderDate(param);
	}

	/**
	 *打烊任务工单
	 * @param queryParam
	 * @return
	 */
	public List<StoreOderInfoVO> storeOrder(PaginationRequest<StoreAppSweepQueryParam> queryParam){
		List<StoreOderInfoVO> response = storeAppSweepService.storeOrder(queryParam);
		return response;
	}

	public StoreOderInfoVO queryOrderDetail(QueryOrderDetailParam queryParam){
		StoreOderInfoVO response = storeAppSweepService.queryOrderDetail(queryParam);
		return response;
	}

	public QueryStoreTaskResponse taskDetail(StoreTaskInfoRequest request) {
		QueryStoreTaskResponse response = storeAppSweepService.taskDetail(request);
		return response;
	}

	public HttpResponse<ScanResponse> taskAcceptance(AcceptanceRequest queryParam) {
		return storeAppSweepService.taskAcceptance(queryParam);
	}

	public Boolean orderAcceptance(AcceptanceOrderRequest request) {
		BladeUser user = Objects.nonNull(AuthUtil.getUser()) ? AuthUtil.getUser() : new BladeUser();
		log.info("BladeUser_user =>:{}", JSON.toJSONString(user));
		request.setUserId(Objects.nonNull(user.getUserId()) ? String.valueOf(user.getUserId()) : "");
		request.setUserName(Objects.nonNull(user.getUserName()) ? user.getUserName() : "门店系统");
		return storeAppSweepService.orderAcceptance(request);
	}
}
